package com.oa.co.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.co.mapper.PurchaseMapper;
import com.oa.co.pojo.Purchase;
import com.oa.co.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Lone Ranger
 */
@Service("purchaseService")
public class PurchaseServiceImpl implements PurchaseService {

    @Autowired
    private PurchaseMapper purchaseMapper;

    @Override
    public Integer addPurchase(Purchase purchase) {
        return purchaseMapper.addPurchase(purchase);
    }

    @Override
    public Integer modifyPurchase(Purchase purchase) {
        return purchaseMapper.modifyPurchase(purchase);
    }

    @Override
    public PageInfo<Purchase> getAllPurchases(Integer page, Integer limit,String purchase_id, String purchase_username, String purchase_dept) {

        PageHelper.startPage(page, limit);

        List<Purchase> purchaseList = purchaseMapper.findPurchaseByCondition(purchase_id, purchase_username,purchase_dept);

        PageInfo<Purchase> pageInfo = new PageInfo<>(purchaseList);
        return pageInfo;
    }

    @Override
    public Integer deletePurchase(String purchase_id) {
        return purchaseMapper.deletePurchase(purchase_id);
    }

    @Override
    public Integer deletePurchaseMulti(List<Purchase> list) {
        return purchaseMapper.deletePurchaseMulti(list);
    }
}
